# -*- mode: python ; coding: utf-8 -*-

import sys
import os
from PyInstaller.building.build_main import Analysis, EXE, PYZ

block_cipher = None

# 获取Python安装路径
python_dir = os.path.dirname(sys.executable)

a = Analysis(
    ['com/francis/api_scanner.py'],
    pathex=[os.getcwd()],  # 使用当前工作目录
    binaries=[],
    datas=[
        ('icon.ico', '.')  # 包含图标文件
    ],
    hiddenimports=[
        'requests',
        'tkinter',
        'urllib3',
        'pkg_resources.py2_warn',
        'pkg_resources.markers'
    ],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

# 正确添加Tcl/Tk运行时文件（使用三元组格式）
a.datas += [
    (os.path.join(python_dir, 'tcl'), 'tcl', 'DATA'),
    (os.path.join(python_dir, 'tk'), 'tk', 'DATA')
]

exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    name='APIScanner',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,  # 使用UPX压缩
    upx_exclude=[],
    runtime_tmpdir=None,
    console=False,  # 不显示控制台窗口
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    icon=os.path.join('icon.ico'),  # 图标路径
)
